#include<linux/module.h>
#include<linux/sched.h>
#include<linux/pid.h>
#include<linux/wait.h>
#include<linux/kthread.h>
MODULE_LICENSE("GPL");

static wait_queue_head_t head;
static wait_queue_t data;
struct task_struct *old_thread;

int my_function(void *argc)
{
	int result=-1;
	printk("in the kernel thread function!\n");
	printk("the current pid is:%d\n",current->pid);
	printk("the state of the parent process before default_wake_function is:%ld\n",old_thread->state);

	if(data.private !=NULL)
	{
		result=default_wake_function(&data,TASK_ALL,0,NULL);	
	}
	printk("the state of the parent process after default_wake_function is:%ld\n",old_thread->state);
	printk("the result of the default_wake_function is:%d\n",result);
	printk("out the kernel thread function\n");
	return 0;
}
static int __init default_wake_function_init(void)
{
	struct task_struct *result;
	int result2=0;
	long result1=0;
	char namefrm[]="default_wake_function";
	printk("into default_wake_function_init.\n");
	old_thread=current;
	result=kthread_create_on_node(my_function,NULL,-1,namefrm);
	wake_up_process(result);

	init_waitqueue_head(&head);
	init_waitqueue_entry(&data,current);
	add_wait_queue(&head,&data);

	result1=schedule_timeout_uninterruptible(1000);

	if(data.private !=NULL)
	{
		result2=default_wake_function(&data,TASK_ALL,0,NULL);	
	}
	printk("the pid of new thread is:%d\n",result->pid);
	printk("the result of the schedule_timeout_uninterruptible is:%ld\n",result1);
	printk("the result of the default_wake_function is:%d\n",result2);
	printk("the current pdi is:%d\n",current->pid);
	printk("out default_wake_function_init.\n");
	return 0;
}
static void __exit default_wake_function_exit(void)
{
	printk("Goodbye default_wake_function\n");
}
module_init(default_wake_function_init);
module_exit(default_wake_function_exit);


